﻿@model List<FYSJcrm.Core.Model.SystemManage.NavigationEntity>
@{
    ViewBag.Title = "添加角色";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<style type="text/css">
    body {
        background: #fff !important;
    }
</style>
<div class="wap-container">
    <div class="panel">
        <div class="panel-body">
            <form class="form form-horizontal" id="form-admin-role-add">
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-2"><span class="c-red">*</span>角色名称：</label>
                    <div class="form-controls col-xs-9 col-sm-10">
                        <input type="text" class="input-text" value="" placeholder="" id="roleName" name="roleName" datatype="*4-16" nullmsg="用户账户不能为空">
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-2">备注：</label>
                    <div class="form-controls col-xs-9 col-sm-10">
                        <input type="text" class="input-text" value="" placeholder="" id="remark" name="remark">
                    </div>
                </div>
                <div class="row clearfix">
                    <label class="form-label col-xs-3 col-sm-2">角色权限：</label>
                    <div class="form-controls col-xs-9 col-sm-10">
                        @foreach (var pnav in Model)
                        {
                            <dl class="Hui-admin-permission-list">
                                <dt>
                                    <label>
                                        <input type="checkbox" value="" name="user-Character-@pnav.Id" id="user-Character-@pnav.Id">
                                        @pnav.Title
                                    </label>
                                </dt>
                                <dd>
                                    @foreach (var cnav in pnav.Childs.Where(n => n.ParentId == pnav.Id))
                                    {
                                        <dl class="clearfix Hui-admin-permission-list2">
                                            <dt>
                                                <label class="">
                                                    <input type="checkbox" value="" name="user-Character-0-@cnav.Id" id="user-Character-0-@cnav.Id">
                                                    @cnav.Title
                                                </label>
                                            </dt>
                                            <dd>
                                                @{ int i = 1;}
                                                @foreach (var per in cnav.ActionType.Split(','))
                                                {
                                                    if (per != "")
                                                    {
                                                        <label class="">
                                                            <input type="checkbox" value="@(cnav + "." + per)" name="perNames" id="user-Character-0-0-@(i++)">
                                                            @FYSJcrm.Core.Common.Utils.ActionType()[per]
                                                        </label>
                                                    }
                                                }
                                            </dd>
                                        </dl>
                                    }
                                </dd>
                            </dl>
                        }
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="col-xs-9 col-sm-10 col-xs-offset-3 col-sm-offset-2">
                        <button type="button" class="btn btn-success radius" id="btnSave" name="btnSave"><i class="icon-ok"></i> 确定</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@section FooterScript
{
    <script type="text/javascript" src="~/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="~/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="~/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript">
        $(function () {
            $(".Hui-admin-permission-list dt input:checkbox").click(function () {
                $(this).closest("dl").find("dd input:checkbox").prop("checked", $(this).prop("checked"));
            });
            $(".Hui-admin-permission-list2 dd input:checkbox").click(function () {
                var l = $(this).parent().parent().find("input:checked").length;
                var l2 = $(this).parents(".Hui-admin-permission-list").find(".Hui-admin-permission-list2 dd").find("input:checked").length;
                if ($(this).prop("checked")) {
                    $(this).closest("dl").find("dt input:checkbox").prop("checked", true);
                    $(this).parents(".Hui-admin-permission-list").find("dt").first().find("input:checkbox").prop("checked", true);
                }
                else {
                    if (l == 0) {
                        $(this).closest("dl").find("dt input:checkbox").prop("checked", false);
                    }
                    if (l2 == 0) {
                        $(this).parents(".Hui-admin-permission-list").find("dt").first().find("input:checkbox").prop("checked", false);
                    }
                }
            });

            $("#form-admin-role-add").validate({
                rules: {
                    roleName: {
                        required: true,
                    },
                }
            });

            $("#btnSave").click(function () {
                let flag = $("#form-admin-role-add").valid();
                if (flag) {
                    const URL = "/PermManage/Role/Add";
                    let formData = $("#form-admin-role-add").serializeArray();

                    //保存
                    savaData(URL, formData);
                }
            })
        });
    </script>
}